/*******************************************************************************
 * AuctionsAction.java
 *
 * Created by Nishan
 * Last modified Date: Sep 12, 2008 3:49:11 PM by nishan
  * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ******************************************************************************/
package com.printeverywhere.action;

import java.io.File;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.printeverywhere.dto.Items;

public class AuctionsAction extends FrontBaseSupport implements ServletRequestAware {

	public AuctionsAction() {
		super(true, false);
		setMyAccount(true);
	}

	private static final long serialVersionUID = 1L;

	private Items items;

	private HttpServletRequest request;

	private HttpServletResponse response;

	private File[] file;
	private String myfileContentType;
	private String myfileFileName;

	/**
	 * @return the file
	 */
	public File[] getFile() {
		return file;
	}

	/**
	 * @param file the file to set
	 */
	public void setFile(File[] file) {
		this.file = file;
	}

	/**
	 * @return the request
	 */
	public HttpServletRequest getRequest() {
		return request;
	}

	/**
	 * @param request the request to set
	 */
	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public String saveUpdateAutionItem() throws Exception{
		for (File path : file) {

//			String contentType = request.getContentType();
//  			System.out.println(contentType);
//  			InputStream is = request.getInputStream();
//
//  			int formDataLength = request.getContentLength();
//
//			FileUtil.fileUpload(contentType, is, formDataLength );
		//}
		/*if(items.getTitle() != null){
			this.items.setUserId(SessionUtil.getUser(request).getId());
			AuctionServiceDelegator.saveAuctionSell(items);
			return SUCCESS;
		}else{
			addActionError("Insert Valida Information required by Auction");
			return INPUT;
		}*/
//			String fullFileName = "c:/upload/myfile.txt";
//
//			File theFile = new File(fullFileName);
//
//			FileUtils.copyFile(upload, theFile);
//
//			} catch (Exception e) {
//
//			addActionError(e.getMessage());
//
//			return INPUT;
//
//			}
		 try{
              	System.out.println("Inside Upload");
              	File destDir = new  File("c:\\");
                System.out.println("File Name:"+this.getMyfileFileName());
                System.out.println("File ContentType:"+this.getMyfileContentType());

                FileUtils.copyFileToDirectory(path, destDir);
                return SUCCESS; // redirect to welcome page.
            }catch(Exception exp){
                LOG.error("File Upload Error:"+  exp);
                this.addActionError("File Upload Error:"+ exp);
                return INPUT;
            }
		}
		return SUCCESS;
}


	/**
	 * @return the items
	 */
	public Items getItems() {
		return items;
	}

	/**
	 * @param items the items to set
	 */
	public void setItems(Items items) {
		this.items = items;
	}

	public void setServletRequest(HttpServletRequest arg0) {
		request = arg0;

	}

	/**
	 * @return the response
	 */
	public HttpServletResponse getResponse() {
		return response;
	}

	/**
	 * @param response the response to set
	 */
	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public String getMyfileContentType() {
		return myfileContentType;
	}

	public void setMyfileContentType(String myfileContentType) {
		this.myfileContentType = myfileContentType;
	}

	public String getMyfileFileName() {
		return myfileFileName;
	}

	public void setMyfileFileName(String myfileFileName) {
		this.myfileFileName = myfileFileName;
	}

}
